package cn.zzn.batch;

import org.apache.tapestry5.ioc.Registry;
import org.apache.tapestry5.ioc.RegistryBuilder;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;

// for test only add begin
import static org.quartz.JobBuilder.*;
import static org.quartz.TriggerBuilder.*;
import static org.quartz.ScheduleBuilder.*;
// for test only add end

import cn.zzn.batch.modules.MiniAppModule;
import cn.zzn.batch.tasks.Job1;

import com.anjlab.tapestry5.services.quartz.QuartzModule;

public class BatchBoard {
	public static void main(String[] args) {
		
		// for test only add begin
//		SimpleSchedule o = null;
		// for test only add end
		
		
		RegistryBuilder builder = new RegistryBuilder();
		builder.add(MiniAppModule.class,
				QuartzModule.class);
		Registry registry = builder.build();
		registry.performRegistryStartup();
		Scheduler scheduler = null;
		try {
			scheduler = registry.getService(Scheduler.class);
			scheduler.start();
			
			JobDetail job = JobBuilder.newJob(Job1.class).withIdentity("job1", "group1").build();
			job.getJobDataMap().put("username", "John Smith");
			
			//for test only begin (study purpose)
			
			//for test only end (study purpose)
			
			Trigger trigger = TriggerBuilder.newTrigger().withIdentity("trigger1", "group1").startNow().build();
			scheduler.scheduleJob(job, trigger);
			
			Thread.sleep(10000);
			scheduler.shutdown();
			
		} catch (Exception e) {
			System.out.println("exception occurs!!!!");
			e.printStackTrace();
		}finally {
			
		}
		
		//for operations done from this thread 
		registry.cleanupThread();
		registry.shutdown();
		
		System.out.println("======executed finished======");
	}
}
